package xyz.scoder;

public class FanHighSpeedCommand implements Command {
    private Fan fan;
    private int odd;

    public FanHighSpeedCommand(Fan fan) {
        this.fan = fan;
    }

    @Override
    public void execute() {
        // 设置新的速度前先保存之前的速度
        odd = fan.getSpeed();
        fan.setSpeed(Fan.HIGH);
        System.out.println("风速：高");
    }

    @Override
    public void undo() {
        fan.setSpeed(odd);
        String speed;
        if (odd == Fan.OFF)
            speed = "关";
        else if (odd == Fan.LOW)
            speed = "低";
        else if (odd == Fan.MEDIAN)
            speed = "中";
        else
            speed = "高";
        System.out.println("风速：" + speed);
    }
}
